package com.bw.mvp.base;

import android.os.Bundle;
import android.widget.Toast;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;

public abstract class BaseMvpActivity<V,P extends BasePresenter<V>> extends AppCompatActivity implements BaseView {
    protected P mPresenter;
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(bindLayout());
        initView();
        mPresenter = createPresenter();
        //绑定view
        if (mPresenter != null){
            mPresenter.attachView((V) this);
        }
        initData();
        initListener();
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        if (mPresenter != null){
            mPresenter.detachView(); //解绑view，防止内存泄露
        }
    }

    public abstract P createPresenter(); //创建presenter

    public abstract int bindLayout();
    public abstract void initView();
    public abstract void initData();
    public abstract void initListener();

    @Override
    public void onOk() {

    }

    @Override
    public void onError() {
        Toast.makeText(this,"数据失败",Toast.LENGTH_LONG).show();
    }

    @Override
    public void showLoading() {
        Toast.makeText(this,"数据加载钟",Toast.LENGTH_LONG).show();
    }

    @Override
    public void hideLoading() {
        Toast.makeText(this,"隐藏数据",Toast.LENGTH_LONG).show();
    }
}
